package hk.ust.android_competition.data_reload_tools;

import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

/**
 * Created by Silver on 2/1/15.
 */
public class TextWriter {
    String path;

    public TextWriter(String path) {
        this.path = path;
    }

    public void write(String data) {
        try {
            File myFile = new File(path);
            if (!myFile.canRead())
                myFile.createNewFile();
            FileOutputStream fOut = new FileOutputStream(myFile);
            OutputStreamWriter myOutWriter =
                    new OutputStreamWriter(fOut);
            myOutWriter.append(data);
            myOutWriter.close();
            fOut.close();
            System.out.println("Save done");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
